<?php

namespace app\api\validate;

use app\common\utils\Is;
use taoser\Validate;

class UserValidate extends Validate
{
    
    protected $rule = [
        'mobile' => 'require|mobile',
        'password' => 'require|length:8,16',
        'repassword' => 'require|length:8,16',
        'code' => 'require|length:6',
        
        
        'nickname' => 'require|max:16',
        'email' => 'require|email',
    ];
    
    protected $message = [
        'mobile.require' => '请输入手机号码',
        'mobile.mobile' => '请输入正确手机号码',
        'mobile.unique' => '手机号码重复',
        'password.require' => '请输入密码',
        'password.length' => '密码在8到16位之间',
        'repassword.require' => '请输入确认密码',
        'repassword.length' => '确认密码在8到16位之间',
        
        'code.require' => '请输入验证码',
        'code.length' => '验证码必须是6位',
        
        
        'nickname.require' => '请输入昵称',
        'nickname.max' => '昵称最多8个字',
        'email.require' => '请输入邮箱地址',
        'email.email' => '请输入正确邮箱地址'
    ];
    
    
    protected $scene = [
        'edit' => ['nickname', 'email'],
        'login' => ['mobile', 'password'],
        'register' => ['mobile', 'password', 'repassword', 'code'],
        'findpassword' => ['mobile', 'password', 'repassword', 'code'],
        'bindMobile' => ['mobile', 'code']
    ];
    
    protected function mobile($value): bool
    {
        return Is::mobile($value);
    }
    
    
}